﻿using B.S.BaseData.Api.Read.Command.OrderCommand;
using B.S.BaseData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WorkOrder.Domain;
using WorkOrder.Domain.DTOs;

namespace B.S.BaseData.Api.Read.Controllers
{
    /// <summary>
    /// 订单管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
        private readonly IMediator mediator;

        public OrderController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取挂号列表
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<ApiPaging<RegistrationOrder>>> GetRegistrationOrder([FromQuery] RegistrationOrderQuerycommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取问诊单列表
        /// </summary>
        /// <param name="request">查询命令</param>
        /// <returns>返回问诊单分页数据</returns>
        [HttpGet]
        public Task<APIResult<ApiPaging<ConsultationOrder>>> GetConsultationOrder([FromQuery] ConsultationOrderQueryCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取问诊单详情（用于反填功能）
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>问诊单详情信息</returns>
        [HttpGet]
        public Task<APIResult<ConsultationOrderDetailDto>> GetConsultationOrderDetail(string orderNumber)
        {
            var command = new GetConsultationOrderDetailCommand { OrderNumber = orderNumber };
            return mediator.Send(command);
        }

        /// <summary>
        /// 获取问诊记录
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>问诊记录信息</returns>
        [HttpGet]
        public Task<APIResult<ConsultationRecordDto>> GetConsultationRecord(string orderNumber)
        {
            var command = new GetConsultationRecordCommand { OrderNumber = orderNumber };
            return mediator.Send(command);
        }

        /// <summary>
        /// 获取挂号单详情（用于反填功能）
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>订单详情信息</returns>
        [HttpGet]
        public Task<APIResult<OrderDetailDto>> GetOrderDetail(string orderNumber)
        {
            var command = new GetOrderDetailCommand { OrderNumber = orderNumber };
            return mediator.Send(command);
        }

        /// <summary>
        /// 获取处方流转订单列表
        /// </summary>
        /// <param name="request">查询命令</param>
        /// <returns>返回处方流转订单分页数据</returns>
        [HttpGet]
        public Task<APIResult<ApiPaging<PrescriptionOrder>>> GetPrescriptionOrder([FromQuery] PrescriptionOrderQueryCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取处方流转订单详情（用于反填功能）
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>处方流转订单详情信息</returns>
        [HttpGet]
        public Task<APIResult<PrescriptionOrderDto>> GetPrescriptionOrderDetail(string orderNumber)
        {
            var command = new GetPrescriptionOrderDetailCommand { OrderNumber = orderNumber };
            return mediator.Send(command);
        }

        /// <summary>
        /// 获取药品订单列表
        /// </summary>
        /// <param name="request">查询命令</param>
        /// <returns>返回药品订单分页数据</returns>
        [HttpGet]
        public Task<APIResult<ApiPaging<MedicineOrder>>> GetMedicineOrder([FromQuery] MedicineOrderQueryCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取药品订单详情（用于反填功能）
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>药品订单详情信息</returns>
        [HttpGet]
        public Task<APIResult<MedicineOrderDto>> GetMedicineOrderDetail(string orderNumber)
        {
            var command = new GetMedicineOrderDetailCommand { OrderNumber = orderNumber };
            return mediator.Send(command);
        }

        /// <summary>
        /// 获取退款申请列表
        /// </summary>
        /// <param name="request">查询命令</param>
        /// <returns>返回退款申请分页数据</returns>
        [HttpGet]
        public Task<APIResult<ApiPaging<RefundApplication>>> GetRefundApplication([FromQuery] RefundApplicationQueryCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取退款申请详情（用于反填功能）
        /// </summary>
        /// <param name="refundId">退款申请ID</param>
        /// <returns>退款申请详情信息</returns>
        [HttpGet]
        public Task<APIResult<RefundApplicationDetailDto>> GetRefundApplicationDetail(string refundId)
        {
            var command = new GetRefundApplicationDetailCommand { RefundId = refundId };
            return mediator.Send(command);
        }

        /// <summary>
        /// 获取物流详情
        /// </summary>
        /// <param name="orderNumber">订单编号</param>
        /// <returns>物流详情信息</returns>
        [HttpGet]
        public Task<APIResult<LogisticsDetailDto>> GetLogisticsDetail(string orderNumber)
        {
            var command = new GetLogisticsDetailCommand { OrderNumber = orderNumber };
            return mediator.Send(command);
        }
    }
}
